Skip to content

Add Pandas to_dict adapter transform #416

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
Apr 17, 2025

Conversation

LarsKue
Copy link
Contributor

@LarsKue LarsKue commented Apr 15, 2025

Usage:

adapter = bf.Adapter().to_dict()
df = pd.DataFrame(...)
adapter(df)
>>> dict(...)

Automatically converts any object and category columns to one-hot encodings.

This is nice for datasets that are based on pandas.DataFrame without requiring too much manual conversion in those datasets. This transform should always be used first, as it assumes the sole input is a pandas.DataFrame.

Docs are still missing, if anyone wants to contribute this feel free to!

@LarsKue LarsKue added feature New feature or request user interface Changes to the user interface and improvements in usability labels Apr 15, 2025
@LarsKue LarsKue self-assigned this Apr 15, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

bayesflow/adapters/transforms/to_dict.py:26

  • [nitpick] Use the existing 'value' variable for type checking instead of re-referencing data[key] to improve clarity. For example, change it to 'if isinstance(value, pd.Series):'.
if isinstance(data[key], pd.Series):

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/adapters/transforms/to_dict.py 87.50% 3 Missing ⚠️
Files with missing lines Coverage Δ
bayesflow/adapters/adapter.py 81.63% <100.00%> (+0.48%) ⬆️
bayesflow/adapters/transforms/__init__.py 100.00% <100.00%> (ø)
bayesflow/adapters/transforms/split.py 78.84% <100.00%> (+0.41%) ⬆️
bayesflow/adapters/transforms/to_array.py 79.16% <100.00%> (ø)
bayesflow/adapters/transforms/to_dict.py 87.50% <87.50%> (ø)

... and 1 file with indirect coverage changes

@LarsKue
Copy link
Contributor Author

LarsKue commented Apr 17, 2025

@paul-buerkner if test pass, could you please add your review and then merge?

Copy link
Contributor

@paul-buerkner paul-buerkner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Waiting for checks to pass and then we can merge.

@paul-buerkner paul-buerkner merged commit c169912 into dev Apr 17, 2025
15 checks passed
@paul-buerkner paul-buerkner deleted the pandas-to-dict-adapter-transform branch April 17, 2025 16:53
@github-project-automation github-project-automation bot moved this from Future to Done in bayesflow development Apr 17, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature New feature or request user interface Changes to the user interface and improvements in usability
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants